/*
  Meanwhile - Unofficial Lotus Sametime client library
  
  Copyright (c) 2007 Christopher O'Brien <siege@preoccupied.net>
  
  License: LGPL
  
  This library is free software; you can redistribute it and/or modify
  it under the terms of version 2 the GNU Library General Public
  License as published by the Free Software Foundation.
                                                                                
  This library is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA
*/


#include "mw-dh.h"
#include <glib.h>


static const guchar[] prime_data = {
  0xCF, 0x84, 0xAF, 0xCE, 0x86, 0xDD, 0xFA, 0x52,
  0x7F, 0x13, 0x6D, 0x10, 0x35, 0x75, 0x28, 0xEE,
  0xFB, 0xA0, 0xAF, 0xEF, 0x80, 0x8F, 0x29, 0x17,
  0x4E, 0x3B, 0x6A, 0x9E, 0x97, 0x00, 0x01, 0x71,
  0x7C, 0x8F, 0x10, 0x6C, 0x41, 0xC1, 0x61, 0xA6,
  0xCE, 0x91, 0x05, 0x7B, 0x34, 0xDA, 0x62, 0xCB,
  0xB8, 0x7B, 0xFD, 0xC1, 0xB3, 0x5C, 0x1B, 0x91,
  0x0F, 0xEA, 0x72, 0x24, 0x9D, 0x56, 0x6B, 0x9F,
};


const MwMPI *mw_dh_get_prime() {
  static MwMPI *m = NULL;

  if(! m) {
    m = mw_mpi_new();
    mw_mpi_import(m, prime_data, 64);
  }

  return m;
}


const MwMPI *mw_dh_get_base() {
  static MwMPI *m = NULL;

  if(! m) {
    m = mw_mpi_new();
    mw_mpi_setul(m, 3);
  }

  return m;
}


void mw_dh_generate_keypair(MwMPI *private, MwMPI *public) {
  mw_mpi_set_random(private, 512);
  mw_mpi_modpow(public, MW_DH_BASE, private, MW_DH_PRIME);
}


void mw_dh_calculate_shared(MwMPI *shared,
			    const MwMPI *remote_public,
			    const MwMPI *local_private) {

  mw_mpi_modpow(shared, remote_public, local_private, MW_DH_PRIME);
}


/* The end. */
